package com.sql.connection;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @Auther: zch
 * @Date: 2019/6/26 14:39
 * @Description: 对原生的Connection 对象进行包装。
 *    属性：既然是对原生的Connection 包装，内部要有原生的属性来接收
 *    行为：sql 连接的行为有关闭连接 跟 sql 查询。
 */
public class SqlConnection {
    private boolean isClose;//是否关闭 （连接的关闭其实是一种逻辑上的关闭，用个boolen 值来做状态标记。）
    private Connection connection;

    public SqlConnection(boolean isClose, Connection connection) {
        this.isClose = isClose;
        this.connection = connection;
    }

    public void close(){
        this.isClose=true;
    }

    public ResultSet query(String sql){
        Statement statement;
        ResultSet resultSet=null;
        try{
           statement=connection.createStatement();
           resultSet=statement.executeQuery(sql);
        }catch (Exception e){

        }
        return resultSet;
    }

    public boolean isClose() {
        return isClose;
    }

    public void setClose(boolean close) {
        isClose = close;
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }
}
